---
title: 'Supplementary Information for "The Cult of the Relevant: International Relations
  Scholars and Policy Engagement Beyond the Ivory Tower"'
date: "January 2023"
output:
  pdf_document: default
  html_notebook: default
code_folding: show
bibliography: references.bib
editor_options:
  chunk_output_type: inline
---

  
\setcounter{table}{0}
\renewcommand{\thetable}{A\arabic{table}}

```{r setup, include=FALSE}



#load libraries. 
library(tidyverse)
library(tidytext)
library(janitor)
library(knitr)
library(tinytex)
library(kableExtra)
library(scales)
library(png)
library(weights)
library(anesrake)

#prevent code and warning messages from appearing in doc. 
knitr::opts_chunk$set(echo = FALSE)
knitr::opts_chunk$set(message = FALSE)
knitr::opts_chunk$set(warning = FALSE)

# Get output document type and use as the format argument in kable function
table_format = if(is_html_output()) {
  "html"
} else if(is_latex_output()) {
  "latex"
}


scholar_pop <- read.csv("population_data.csv")

snap_scholar <- read.csv("survey_data.csv")



#reformat demo variables as factors for survey weights
snap_scholar <- snap_scholar %>%
  mutate(gender_expanded = gender) %>% 
  mutate(gender = factor(gender, levels = c("Male", "Female")), 
         MC = factor(MC, levels =c("0", "1")), 
         type = factor(type, levels = c("National Liberal Arts College" , "National Research University" , "Regional Liberal Arts College" , "Regional Research University", "Other")),  
         academic_rank = factor(academic_rank, levels=c("Full Professor", "Associate Professor", "Assistant Professor", "Instructor, Lecturer, Adjunct, Visiting, or Other")))
scholar_pop <- scholar_pop %>%
  mutate(gender_expanded = gender) %>% 
  mutate(gender = factor(gender, levels = c("Male", "Female")), 
         MC = factor(MC, levels =c("0", "1")), 
         type = factor(type, levels=c("National Liberal Arts College" , "National Research University" , "Regional Liberal Arts College" , "Regional Research University", "Other")),  
         academic_rank = factor(academic_rank, levels = c("Full Professor", "Associate Professor", "Assistant Professor", "Instructor, Lecturer, Adjunct, Visiting, or Other")))



## Check the distributions of our demo vars in pop and survey
#pop
pop_gender_dist <- wpct(scholar_pop$gender)
pop_mc_dist <- wpct(scholar_pop$MC)
pop_type_dist <- wpct(scholar_pop$type)
pop_rank_dist <- wpct(scholar_pop$academic_rank)

#sample
korbel_gender_dist <- wpct(snap_scholar$gender)
korbel_mc_dist <- wpct(snap_scholar$MC)
korbel_type_dist <- wpct(snap_scholar$type)
korbel_rank_dist <- wpct(snap_scholar$academic_rank)

#check for correspondence in levels between the pop and scholar
#gender
rbind(pop_gender_dist, korbel_gender_dist)
#monkey cage
rbind(pop_mc_dist, korbel_mc_dist)
#type 
rbind(pop_type_dist, korbel_type_dist)
#rank
rbind(pop_rank_dist, korbel_rank_dist)

snap_scholar$weight_id = 1:nrow(snap_scholar)
#anesrake wants a dataframe
snap_scholar <- as.data.frame(snap_scholar)

#target proportions - assign the weight targets
targets <- list(pop_gender_dist, pop_mc_dist, pop_type_dist, pop_rank_dist)
names(targets) <- c("gender", "MC", "type", "academic_rank")
anesrakefinder(targets, snap_scholar, choosemethod = "total")

rakeout <- anesrake(targets, snap_scholar, caseid = snap_scholar$weight_id,
                    verbose= TRUE, cap = 5, choosemethod = "total",
                    type = "pctlim", pctlim = .05 , nlim = 5,
                    iterate = TRUE , force1 = TRUE)
 
summary(rakeout)

weighted_data <- cbind(snap_scholar, rakeout[1])

summary_rake <- weightassess(targets, snap_scholar, weighted_data$weightvec)

weighted_data <- weighted_data %>% 
  mutate(tenured = case_when(academic_rank ==  "Full Professor" | academic_rank == "Associate Professor"  ~ "Tenured",  !is.na(academic_rank) ~ "Untenured")) %>%
                    mutate(r1 = case_when(type == "National Research University" ~ "R1", 
                                                        !is.na(type) ~ "Non-R1")) %>% 
                    mutate(primary_method = factor(primary_method, levels = c("Quantitative analysis","Qualitative analysis", "Policy analysis", "Experimental", "Other", "Legal or ethical analysis", "Counterfactual analysis", "Formal modeling", "Pure theory")))
            
## gender 


gender_resp <- select(snap_scholar,gender_expanded) %>%
  filter(gender_expanded!="") %>% 
  tabyl(gender_expanded) %>%
  adorn_totals() %>%
  adorn_pct_formatting() 

gender_pop <- select(scholar_pop,gender_expanded)%>%
  filter(gender_expanded !="") %>% 
  tabyl(gender_expanded) %>%
  adorn_totals() %>%
  adorn_pct_formatting() %>% left_join(gender_resp,by= "gender_expanded")



gender_resp_limited <- select(snap_scholar,gender) %>%
  filter(gender!="") %>% 
  tabyl(gender) %>%
  adorn_totals() %>%
  adorn_pct_formatting() 

gender_pop_limited <- select(scholar_pop,gender)%>%
  filter(gender !="") %>% 
  tabyl(gender) %>%
  adorn_totals() %>%
  adorn_pct_formatting() %>% left_join(gender_resp_limited,by= "gender")


gender_test <- gender_pop_limited %>% select(n.x, n.y)
gender_test <-  stats::chisq.test(gender_test) 
gender_test <- paste0("$X^2$ (",  gender_test$parameter[[1]], ") = ", round(gender_test$statistic[[1]], 2), ", $p = $",  round(gender_test$p.value, 3), ".")

## rank 
rank_resp <- select(snap_scholar,academic_rank) %>%
  filter(academic_rank!="") %>% 
  tabyl(academic_rank) %>%
  adorn_totals() %>%
  adorn_pct_formatting() 

rank_pop <- select(scholar_pop,academic_rank)%>%
  filter(academic_rank!="") %>% 
  tabyl(academic_rank) %>%
  adorn_totals() %>%
  adorn_pct_formatting() %>% left_join(rank_resp,by= "academic_rank")


rank_test <- rank_pop %>% select(n.x, n.y)
rank_test <-  stats::chisq.test(rank_test) 
rank_test <- paste0("$X^2$ (",  rank_test$parameter[[1]], ")=", round(rank_test$statistic[[1]], 2), ", $p<.0001$.")


## univeristy type  
type_resp <- select(snap_scholar,type) %>%
  filter(type!="") %>% 
  tabyl(type) %>%
  adorn_totals() %>%
  adorn_pct_formatting() 

type_pop <- select(scholar_pop,type)%>%
  filter(type!="") %>% 
  tabyl(type) %>%
  adorn_totals() %>%
  adorn_pct_formatting() %>% left_join(type_resp,by= "type")

type_test <- type_pop %>% select(n.x, n.y)
type_test <-  stats::chisq.test(type_test) 
type_test <- paste0("$X^2$ (",  type_test$parameter[[1]], ")=", round(type_test$statistic[[1]], 2), ", $p=",  round(type_test$p.value, 3), "$.")



## univeristy type  
MC_resp <- select(snap_scholar,MC) %>%
  filter(MC!="") %>% 
  tabyl(MC) %>%
  adorn_totals() %>%
  adorn_pct_formatting() 

MC_pop <- select(scholar_pop,MC)%>%
  filter(MC!="") %>% 
  tabyl(MC) %>%
  adorn_totals() %>%
  adorn_pct_formatting() %>% 
  left_join(MC_resp,by= "MC") %>%
  mutate(MC = case_when(MC == 0 ~ "No", MC == 1 ~ "Yes", TRUE ~ MC))



MC_test <- MC_pop %>% select(n.x, n.y)
MC_test <-  stats::chisq.test(MC_test) 
MC_test <- paste0("$X^2$ (",  MC_test$parameter[[1]], ")=", round(MC_test$statistic[[1]], 2), ", $p<.001$.")



```
\clearpage 
# Comparison of our respondents to the population

We attempted to contact all IR scholars working at colleges or universities in the United States. We began with the list of colleges and universities tracked by U.S. News and World Report. Teams of research assistants visited the website of each institution and collected contact information for all individuals with primary appointments in political science, government, international affairs, social science, or public policy departments, programs, or schools who teaches or publishes research issues that cross international borders. Of the 5,251 scholars across the U.S. that we successfully contacted, 971 responded to at least one question. The resulting response rate is approximately 18.5 percent.  We have data on the following publicly observable characteristics of both the population of IR scholars in the United States and the subset of IR scholars who responded to our survey: gender, rank, university type, and whether or not they have published in the Monkey Cage since it moved to the Washington Post in 2013. 

The distribution of these variables is given in the table below. While the our respondents were statistically significantly more likely to be male, tenured, and to have published in the Monkey Cage, the magnitudes of these differences were generally small in absolute terms. 

```{r gender_dist, include=TRUE}

gender_pop %>% 
  kable(col.names= c("Gender", "Count", "Percentage" ,"Count", "Percentage" ), 
        caption = "Distribution of gender among population and respondents.",
        booktabs = TRUE, format.args = list(big.mark = ","), format = table_format) %>%
   add_header_above(c("",  "Population" = 2, "Respondents" = 2))  %>% kable_styling(latex_options = "HOLD_position", ) %>%
  footnote(general = gender_test, general_title = "",  escape = FALSE)


```


```{r rank_dist, include=TRUE}

rank_pop %>% 
  kable(col.names= c("Rank", "Count", "Percentage" ,"Count", "Percentage" ), 
        caption = "Distribution of academic rank among population and respondents.",
        booktabs = TRUE, format.args = list(big.mark = ",")) %>%
   add_header_above(c("",  "Population" = 2, "Respondents" = 2))  %>% kable_styling(latex_options = "HOLD_position") %>%
  footnote(general = rank_test, general_title = "",  escape = FALSE)


```


```{r type_dist, include=TRUE}

type_pop %>% 
  kable(col.names= c("Inst. type", "Count", "Percentage" ,"Count", "Percentage" ), 
        caption = "Distribution of U.S News institution type among population and respondents.",
        booktabs = TRUE, format.args = list(big.mark = ",")) %>%
   add_header_above(c("",  "Population" = 2, "Respondents" = 2))  %>% kable_styling(latex_options = "HOLD_position") %>%
   footnote(general = type_test, general_title = "",  escape = FALSE)


```


```{r MC_dist, include=TRUE}

MC_pop %>% 
  kable(col.names= c("Monkey cage publication?", "Count", "Percentage" ,"Count", "Percentage" ), 
        caption = "Distribution of Monkey Cage publication status among population and respondents.",
        booktabs = TRUE, format.args = list(big.mark = ",")) %>%
   add_header_above(c("", "Population" = 2, "Respondents" = 2))  %>% kable_styling(latex_options = "HOLD_position") %>%
 footnote(general = MC_test, general_title = "",  escape = FALSE)


```


\clearpage 

# Weighting the sample

We use post-stratification weights to bring the distribution of gender, rank, and Monkey Cage activity among our respondents in line with that of the population. We use the "anesrake" package @pasek2018package which implements the weighting algorithm outlined by @debell2009computing.

```{r weighted_descriptives , include=TRUE}


summary_rake$gender %>% as_tibble(rownames="Gender") %>%
  select(Gender, Target, `Unweighted %`, `Wtd %` ) %>%
  rename(Population = Target) %>%
  mutate(across(Population:`Wtd %`, ~ paste0(round(.x * 100,2), "%"))) %>%
   kable(caption = "Distribution of gender before and after weighting",
        booktabs = TRUE, format.args = list(big.mark = ",")) %>% kable_styling(latex_options = "HOLD_position") 
  

summary_rake$MC %>% as_tibble(rownames="MC") %>%
  select(MC, Target, `Unweighted %`, `Wtd %` ) %>%
  rename(Population = Target) %>%
  mutate(MC = case_when(MC == 1 ~ "Yes", MC == 0 ~ "No", MC == "Total" ~ "Total")) %>%
  mutate(across(Population:`Wtd %`, ~ paste0(round(.x * 100,2), "%"))) %>%
   kable(caption = "Distribution of Monkey Cage activity before and after weighting",
        booktabs = TRUE, format.args = list(big.mark = ",")) %>% kable_styling(latex_options = "HOLD_position") 



summary_rake$academic_rank %>% as_tibble(rownames="Rank") %>%
  select(Rank, Target, `Unweighted %`, `Wtd %` ) %>%
  rename(Population = Target) %>%
  mutate(across(Population:`Wtd %`, ~ paste0(round(.x * 100,2), "%"))) %>%
   kable(caption = "Distribution of academic rank before and after weighting",
        booktabs = TRUE, format.args = list(big.mark = ",")) %>% kable_styling(latex_options = "HOLD_position") 


summary_rake$type %>% as_tibble(rownames="Institution Type") %>%
  select(`Institution Type`, Target, `Unweighted %`, `Wtd %` ) %>%
  rename(Population = Target) %>%
  mutate(across(Population:`Wtd %`, ~ paste0(round(.x * 100,2), "%"))) %>%
   kable(caption = "Distribution of academic rank before and after weighting",
        booktabs = TRUE, format.args = list(big.mark = ",")) %>% kable_styling(latex_options = "HOLD_position") 
  
```



\newpage



# Analyses with weighted and unweighted data  


Here we reproduce the analyses included in the manuscript along with versions using the weighted data. The conclusions we draw do not depend on whether we weight the data or not. For this first table, we also report the sub-samples based on whether or not the respondent had previously published in the Monkey Cage. 


## Manuscript Table 2


```{r table2 , include=TRUE}
  
#  Q2 Which of the following types of policy organizations have you worked with/for? Check all that apply.
#▢	U.S. government (including military service)  (1) 
#▢	Foreign government (including military service)  (2) 
#▢	Interest group  (3) 
#▢	International organization  (4) 
#▢	NGO  (5) 
#▢	Private sector  (6) 
#▢	Think tank  (7) 
#▢	⊗None  (8) 

pastwork_opts <-c("U.S. government (including military service)", "Foreign government (including military service)", "Interest group", "International organization", "NGO", "Private sector", "Think tank", "None")


table2_unweighted <- weighted_data %>%  filter(!is.na(Q2)) %>%
  rowid_to_column("ID") %>%
  select(ID, Q2) %>%
  separate_rows(Q2, sep=",") %>%
  mutate(Q2 = str_trim(Q2)) %>%
  mutate(n_resp = length(unique(ID))) %>%
  group_by(Q2) %>%
  mutate(Q2 = factor(Q2, levels=pastwork_opts)) %>%
  summarise(n_selected = n(), total_n = first(n_resp)) %>%
  mutate(pct = round((n_selected/total_n*100), digits=1)) %>%
  filter(!is.na(Q2)) %>% 
  arrange(-pct) %>%
  mutate(pct = paste0(as.character(pct), "%")) 


table2_weighted <- weighted_data %>% filter(!is.na(Q2)) %>%
  rowid_to_column("ID") %>%
  select(ID, Q2, weightvec) %>%
  mutate(n_resp_wght = sum(weightvec)) %>%
  separate_rows(Q2, sep=",") %>%
  mutate(Q2 = str_trim(Q2)) %>%
  group_by(Q2) %>%
  mutate(Q2 = factor(Q2, levels=pastwork_opts)) %>%
  summarise(n_selected = sum(weightvec), total_n = first(n_resp_wght)) %>%
  mutate(pct = round((n_selected/total_n*100), digits=1)) %>%
  filter(!is.na(Q2)) %>% 
  arrange(-pct) %>%
  mutate(pct = paste0(as.character(pct), "%")) 


table2_MC <- weighted_data %>%  filter(!is.na(Q2) & MC == 1) %>%
  rowid_to_column("ID") %>%
  select(ID, Q2) %>%
  separate_rows(Q2, sep=",") %>%
  mutate(Q2 = str_trim(Q2)) %>%
  mutate(n_resp = length(unique(ID))) %>%
  group_by(Q2) %>%
  mutate(Q2 = factor(Q2, levels=pastwork_opts)) %>%
  summarise(n_selected = n(), total_n = first(n_resp)) %>%
  mutate(pct = round((n_selected/total_n*100), digits=1)) %>%
  filter(!is.na(Q2)) %>% 
  arrange(-pct) %>%
  mutate(pct = paste0(as.character(pct), "%")) 


### combined table for text

combined_tbl2 <- table2_unweighted %>% select(Q2, pct) %>%
  left_join(select(table2_weighted, Q2, pct), by = "Q2") %>%
  left_join(select(table2_MC, Q2, pct), by = "Q2") %>%
  add_row(Q2 = "N", pct.x = as.character(table2_unweighted[[1,3]]), pct.y = as.character(round(table2_weighted[[1,3]],0)), pct = as.character(table2_MC[[1,3]])) %>%
  kable(caption = "Which of the following types of policy organizations have you worked with/for?", 
        booktabs = TRUE, 
        linesep = "",
        digit = 2, 
        col.names= c("Response option", "Unweighted", "Weighted", "MC authors only"))  %>% 
  kable_styling(latex_options = "HOLD_position") 

 combined_tbl2 

```

## Results discussed in the text

From the manuscript: "For many academics, their engagement spanned organizational types: roughly a third (32.2%) reported engaging with multiple organizational types..."

```{r in_text1 , include=TRUE}

multiple_orgs<- weighted_data %>%  filter(!is.na(Q2)) %>%
  rowid_to_column("ID") %>%
  select(ID, Q2) %>%
  separate_rows(Q2, sep=",") %>%
  mutate(Q2 = str_trim(Q2)) %>%
  mutate(n_resp = length(unique(ID))) %>%
  group_by(Q2) %>% filter(Q2 != "None") %>% 
  group_by(ID) %>% summarise(n_selected = n(), n_answered = first(n_resp)) 

multiple_orgs %>% 
  filter(n_selected != 1) %>%
  group_by(n_selected) %>% 
  summarise(more_than_one = n(), n_answered = first(n_answered), pct = more_than_one/n_answered) %>% 
  summarise(pct = round(sum(pct),3)*100)  %>% 
  kable(caption = "", 
        booktabs = TRUE, 
        linesep = "",
        digit = 2, 
        col.names= c("Percent"))  %>% 
  kable_styling(latex_options = "HOLD_position") 

```


From the manuscript:  "...and about 14 percent worked for or with three or more different organizational types..."

```{r in_text2 , include=TRUE}

multiple_orgs %>% filter(n_selected > 2) %>% group_by(n_selected) %>% summarise(more_than_one = n(), n_answered = first(n_answered), pct = more_than_one/n_answered) %>% summarise(pct = round(sum(pct), 3)*100)  %>%
  kable(caption = "", 
        booktabs = TRUE, 
        linesep = "",
        digit = 2, 
        col.names= c("Percent"))  %>% 
  kable_styling(latex_options = "HOLD_position") 
```

From the manuscript: "Nearly half (47.7%) of survey respondents had worked in the policy world before entering academia. And these positions were not just of the short-term summer internship variety: 37.7% of this group had held positions for six months or more. "

```{r in_text3 , include=TRUE}

weighted_data %>% tabyl(Q1, show_na = FALSE) %>% adorn_pct_formatting()  %>% kable(caption = "", 
        booktabs = TRUE, 
        linesep = "",
        digit = 2, 
        col.names= c("Response option" , "N", "Percent"))  %>% 
  kable_styling(latex_options = "HOLD_position") 
```


From the manuscript: "When asked how frequently they engaged in these activities over the past five years, a majority (58.3%) indicated they engaged in these activities at least several times a year; 15.7% responded that they engaged monthly."

```{r in_text4 , include=TRUE}

weighted_data %>% tabyl(Q5, show_na = FALSE) %>% adorn_pct_formatting()   %>% kable(caption = "", 
        booktabs = TRUE, 
        linesep = "",
        digit = 2, 
        col.names= c("Response option" , "N", "Percent"))  %>% 
  kable_styling(latex_options = "HOLD_position") 

```


From the manuscript: 

>"When IR scholars engage, what types of activities do they engage in? As we expected (H1), the most frequent modalities of engagement were those that provide opportunities for credit-claiming/enhancing scholar name recognition and that require relatively small investments of time: media appearances or interviews (68.7%) and op-ed/blog writing (63.0%). ... “Deeper” engagement modalities, such as holding a full-time position in a government agency, multilateral organization, advocacy organization, think tank, or interning for some, were much less frequent (19.0% and 11.6%, respectively). ... Nevertheless, sizable minorities (48.8% and 40.5% respectively) reported that they engage in consulting activities not for attribution/publication and writing policy briefs for government agencies, advocacy organizations, or think tanks.  "

```{r in_text5 , include=TRUE}

perc<-function(x,...){
  x %>% group_by(...) %>% summarise(n=n()) %>% drop_na() %>% mutate(sum=sum(n),per=round((n/sum)*100,2)) %>% select(-sum)
}


weighted_data$Q4<-gsub(", ","/",weighted_data$Q4)
Q4<-weighted_data %>% tidyr::separate(Q4,paste0("Q4_",1:7),",") %>% select(ResponseId,Q4_1:Q4_7) %>% gather(Q,Q4,Q4_1:Q4_7) %>% drop_na() %>% mutate(sum=n_distinct(ResponseId)) %>% group_by(Q4,sum) %>% summarise(n=n()) %>% mutate(per=round((n/sum)*100,2)) %>% select(-sum)
names(Q4)<-c("Response","N","Percentage")


Q4<-Q4[c(1,2,3,4,6,8,9,7,5),]


Q4$Percentage <- scales::percent((Q4$Percentage/100))
column_names <- c("Response option", "Count", "Percentage")



knitr::kable(Q4[1:9,], caption="In which of the following types of policy-related activities have you participated in your professional capacity as a scholar? Check all that apply.", 
        booktabs=TRUE, 
        linesep = "",
        col.names = column_names,
        digits = 2,
        align=c("l", "r", "r", "r")
  ) %>% kable_styling(latex_options = "hold_position", full_width = TRUE) 



```

\clearpage

From the manuscript: "In total, 70% of respondents believe that policy engagement enhances the quality of their teaching and research."

```{r in_text6 , include=TRUE}

weighted_data %>% mutate(enchance_teaching_research = case_when(
  Q9_3 == "Agree" | Q9_3 == "Strongly agree" ~ "Agree", 
  !is.na(Q9_3) ~ "No opinion or disagree")) %>% 
  tabyl(enchance_teaching_research, show_na = FALSE) %>% 
  adorn_pct_formatting()  %>% kable(caption = "", 
        booktabs = TRUE, 
        linesep = "",
        digit = 2, 
        col.names= c("Response option" , "N", "Percent"))  %>% 
  kable_styling(latex_options = "HOLD_position") 

```




## Manuscript Table 3 
```{r table3 , include=TRUE}


# Q5 In the past five years, how frequently have you engaged in the policy-related activities that you identified above?
# o	Monthly  (1) 
# o	Several times a year  (2) 
# o	Once every few years  (3) 
# o	Never  (4) 

weighted_data %>% filter(!is.na(Q5) & !is.na(r1) & !is.na(tenured)) %>% 
  mutate(Q5_recode = case_when(
          Q5 == "Monthly" | Q5 == "Several times a year" ~ "Monthly or several times a year", 
          !is.na(Q5) ~ "Less than monthly")) %>%
  select(Q5_recode, tenured, r1) %>%
  group_by(tenured, r1) %>%
  mutate(tenure_r1_n = n()) %>%
  group_by(Q5_recode, tenured, r1) %>%
  mutate(count = n()) %>% 
  mutate(pct = count/tenure_r1_n)  %>%
  summarise(Q5_recode = first(Q5_recode), tenured = first(tenured), r1 = first(r1), tenure_r1_n = first(tenure_r1_n), count = first(count), pct = first(pct) ) %>%
  filter(Q5_recode == "Monthly or several times a year") %>%
  group_by(tenured,r1) %>%
  select(tenured, r1, pct) %>%
  mutate(pct = paste0(round(pct*100, 1), "%")) %>%
  pivot_wider(names_from = r1, values_from = pct) %>%
    kable(caption="[Unweighted] Frequency of Engagement by Junior Scholars, R1 vs. Other Institutional Types.",
        linesep = "",
        booktabs = TRUE,
        col.names= c("Tenure status", "Non-R1", "R1"),
        digits = 1) %>%kable_styling(latex_options = "HOLD_position") 

weighted_data %>% filter(!is.na(Q5) & !is.na(r1) & !is.na(tenured)) %>% 
  mutate(Q5_recode = case_when(
          Q5 == "Monthly" | Q5 == "Several times a year" ~ "Monthly or several times a year", 
          !is.na(Q5) ~ "Less than monthly")) %>%
  select(Q5_recode, tenured, r1, weightvec) %>%
  group_by(tenured, r1) %>%
  mutate(tenure_r1_n = sum(weightvec)) %>%
  group_by(Q5_recode, tenured, r1) %>%
  mutate(count = sum(weightvec)) %>% 
  mutate(pct = count/tenure_r1_n)  %>%
  summarise(Q5_recode = first(Q5_recode), tenured = first(tenured), r1 = first(r1), tenure_r1_n = first(tenure_r1_n), count = first(count), pct = first(pct) ) %>%
  filter(Q5_recode == "Monthly or several times a year") %>%
  group_by(tenured,r1) %>%
  select(tenured, r1, pct) %>%
  mutate(pct = paste0(round(pct*100, 1), "%")) %>%
  pivot_wider(names_from = r1, values_from = pct) %>%
    kable(caption="[Weighted] Frequency of Engagement by Junior Scholars, R1 vs. Other Institutional Types.",
        linesep = "",
        booktabs = TRUE,
        col.names= c("Tenure status", "Non-R1", "R1"),
        digits = 1) %>% kable_styling(latex_options = "HOLD_position") 
```

From the manuscript: "Seniority appears to result in more frequent engagement in a roughly linear fashion. Seventy-four percent of chaired professors reported engaging either monthly or several times a year in the previous five years, with full professors (59%), associate professors (57%), and assistant professors (52%) engaging less frequently. Assistant professors engage the least frequently of those on the tenure track, but the majority still choose to do so at least several times a year. "

```{r in_text7 , include=TRUE}

weighted_data %>% mutate(Q5_recode = case_when(
          Q5 == "Monthly" | Q5 == "Several times a year" ~ "Monthly or several times a year", 
          !is.na(Q5) ~ "Less than monthly")) %>% 
          filter(academic_rank_raw == "Assistant Professor" | academic_rank_raw == "Associate Professor" | academic_rank_raw == "Full Professor" | academic_rank_raw == "Chaired Professor" ) %>%
  tabyl(academic_rank_raw, Q5_recode, show_na = FALSE)  %>% adorn_percentages()  %>% adorn_pct_formatting() %>% adorn_ns()    %>% 
  kable(caption = "", 
        booktabs = TRUE, 
        linesep = "",
        digit = 2, 
        col.names= c("Rank" , "Less than monthly", "Monthly or several times a year"))  %>% 
  kable_styling(latex_options = "HOLD_position") 


```

From the manuscript: "Female IR scholars engage at least several times a year at higher rates (63.4%%) than their male counterparts (56.5%)..." 

```{r in_text8 , include=TRUE}

weighted_data %>% mutate(Q5_recode = case_when(
          Q5 == "Monthly" | Q5 == "Several times a year" ~ "Monthly or several times a year", 
          !is.na(Q5) ~ "Less than monthly")) %>% 
  tabyl(gender, Q5_recode, show_na = FALSE)  %>% adorn_percentages()  %>% adorn_pct_formatting() %>% adorn_ns()  %>%
  kable(caption = "", 
        booktabs = TRUE, 
        linesep = "",
        digit = 2, 
        col.names= c("Gender" , "Less than monthly", "Monthly or several times a year"))  %>% 
  kable_styling(latex_options = "HOLD_position") 


```

From the manuscript: "...although male scholars engage monthly at slightly higher rates (16.4% vs. 13.8%)."


```{r in_text9 , include=TRUE}

weighted_data %>%
  tabyl(gender, Q5, show_na = FALSE)  %>% adorn_percentages()  %>% adorn_pct_formatting() %>% adorn_ns() %>%
  kable(caption = "", 
        booktabs = TRUE, 
        linesep = "",
        digit = 2, 
        col.names= c("Rank" , "Monthly", "Never", "Once every few years", "Several times a year"))  %>% 
  kable_styling(latex_options = "HOLD_position") 


```

From the manuscript: "The gap in monthly engagement may be partially attributable to the gender gap in chaired professors; chaired professors accounted for 12.6% of male respondents but only 8.9% of female respondents..."

```{r in_text10 , include=TRUE}

weighted_data %>%
  tabyl(gender, academic_rank_raw, show_na = FALSE)  %>% adorn_percentages("row")  %>% adorn_pct_formatting() %>% adorn_ns()  %>%
  kable(caption = "", 
        booktabs = TRUE, 
        linesep = "",
        digit = 2, 
        col.names= c("Gender", "Adjunct/Visiting", "Assistant", "Associate", "Chaired", "Full", "Instructor", "Other"))  %>% 
  kable_styling(latex_options = "HOLD_position") 


```

From the manuscript: "...and the gender gap in chaired professorships (79.6% male vs. 20.4% female) is larger than for any other academic rank. "

```{r in_text11 , include=TRUE}

weighted_data %>%
  tabyl(gender, academic_rank_raw, show_na = FALSE)  %>% adorn_percentages("col")  %>% adorn_pct_formatting() %>% adorn_ns()   %>%
  kable(caption = "", 
        booktabs = TRUE, 
        linesep = "",
        digit = 2, 
        col.names= c("Gender", "Adjunct/Visiting", "Assistant", "Associate", "Chaired", "Full", "Instructor", "Other"))  %>% 
  kable_styling(latex_options = "HOLD_position") 
```

From the manuscript: "However, the difference between male and female rates of engagement was not statistically significant, either across ranks (Pearson chi2(3)=2.51, Pr = 0.455)..."

```{r in_text12 , include=TRUE}

test <- weighted_data %>% filter(Q5 == "Monthly" | Q5 == "Several times a year") %>% 
   filter(academic_rank_raw == "Assistant Professor" | academic_rank_raw == "Associate Professor" | academic_rank_raw == "Full Professor" | academic_rank_raw == "Chaired Professor" ) %>%
  tabyl(gender,  academic_rank_raw, show_na = FALSE)  #%>% adorn_percentages("col")  %>% adorn_pct_formatting() %>% adorn_ns() 

chisq.test(test)


```



From the manuscript: "...or at the junior/untenured level (Pearson chi2(1)=.354, Pr=0.552)"

```{r in_text13 , include=TRUE}

test <- weighted_data %>% filter(Q5 == "Monthly" | Q5 == "Several times a year") %>% 
  tabyl(gender,  tenured, show_na = FALSE)  #%>% adorn_percentages("col")  %>% adorn_pct_formatting() %>% adorn_ns() 

chisq.test(test)


```




## Manuscript Table 4


```{r table4, include=TRUE}

#Q5 In the past five years, how frequently have you engaged in the policy-related activities that you identified above?
#o	Monthly  (1) 
#o	Several times a year  (2) 
#o	Once every few years  (3) 
#o	Never  (4) 



###Unweighted 


#all scholars
table4_full_sample <- weighted_data %>% filter(!is.na(Q5) & !is.na(primary_method)) %>% 
  select(Q5, primary_method,secondary_method) %>%
  filter(primary_method == "Qualitative analysis" | primary_method == "Quantitative analysis" | str_detect(secondary_method, "Quantitative analysis")) %>%
  
  mutate(primary_method = case_when(str_detect(secondary_method, "Quantitative analysis") & primary_method != "Qualitative analysis"  ~ "Quantitative analysis", 
                                    TRUE ~ as.character(primary_method))) %>%
  group_by(primary_method) %>%
 # mutate(primary_method = factor(primary_method, levels = c("Qualitative analysis", "Quantitative analysis"))) %>%
  mutate(method_n = n()) %>%
  group_by(Q5,method_n) %>%
  mutate(count = n()) %>% 
  mutate(pct = count/method_n)  %>%
 mutate(pct = paste0(round(pct*100, 1), "%")) %>%
  summarise(Q5 = first(Q5), primary_method=first(primary_method), pct = first(pct), method_n = first(method_n), count = first(count)) %>%
  mutate(issue = "All")

#International/Global Security
table4_igs_sample <- weighted_data %>% filter(!is.na(Q5) & !is.na(primary_method) & Q43 == "International/Global Security") %>% 
  select(Q5, primary_method, secondary_method) %>%
   filter(primary_method == "Qualitative analysis" | primary_method == "Quantitative analysis" | str_detect(secondary_method, "Quantitative analysis")) %>%
  
  mutate(primary_method = case_when(str_detect(secondary_method, "Quantitative analysis") & primary_method != "Qualitative analysis"  ~ "Quantitative analysis", 
                                    TRUE ~ as.character(primary_method))) %>%
  group_by(primary_method) %>%
  mutate(method_n = n()) %>%
  group_by(Q5,method_n) %>%
  mutate(count = n()) %>% 
  mutate(pct = count/method_n)  %>%
 mutate(pct = paste0(round(pct*100, 1), "%")) %>%
  summarise(Q5 = first(Q5), primary_method=first(primary_method), pct = first(pct), method_n = first(method_n), count = first(count))  %>%
  mutate(issue = "International/Global Security")


#get ns for bottom row 
method_n_igs <- table4_igs_sample  %>% select(primary_method, method_n) %>% pivot_wider(names_from = primary_method, values_from = method_n) %>% mutate(across(everything(), as.character))
method_n <- table4_full_sample  %>% select(primary_method, method_n) %>% pivot_wider(names_from = primary_method, values_from = method_n) %>% mutate(across(everything(), as.character))
method_ns <- cbind(method_n[1,2:3],  method_n_igs[1,2:3])
#get tables
table4_igs_sample <- table4_igs_sample %>% select(Q5, primary_method, pct) %>% pivot_wider(names_from = primary_method, values_from = pct)
table4_full_sample <- table4_full_sample %>% select(Q5, primary_method, pct) %>% pivot_wider(names_from = primary_method, values_from = pct)
#create full table
table4_full_table <-  table4_full_sample %>% left_join(table4_igs_sample, by = "Q5") %>%
  mutate(Q5 = factor(Q5, levels = c("Monthly", "Several times a year", "Once every few years", "Never"))) %>% 
  arrange(Q5)
#force ns to conform 
method_ns <- cbind("N", method_ns) 
colnames(method_ns) = colnames(table4_full_table) 
##add Ns to table
table4_full_table <- table4_full_table %>% bind_rows(method_ns)

table4<- table4_full_table %>% kable(
  col.names= c("Engagement freq.", "Quantitative", "Qualitative", "Quantitative ", "Qualitative"), 
  caption= "In the past five years, how frequently have you engaged in the policy-related activities that you identified above?", 
  booktabs = TRUE)  %>% 
  add_header_above(c("", "All scholars" = 2, "International/Global Security" = 2)) %>% 
  kable_styling(latex_options = "HOLD_position") 


table4
# need to figure out how to add the Ns here. 



###Weighted 
#all scholars
weight_table4_full_sample <- weighted_data %>% filter(!is.na(Q5) & !is.na(primary_method)) %>% 
  select(Q5, primary_method, secondary_method, weightvec) %>%
  filter(primary_method == "Qualitative analysis" | primary_method == "Quantitative analysis" | str_detect(secondary_method, "Quantitative analysis")) %>%
  
  mutate(primary_method = case_when(str_detect(secondary_method, "Quantitative analysis") & primary_method != "Qualitative analysis"  ~ "Quantitative analysis", 
                                    TRUE ~ as.character(primary_method))) %>%
  group_by(primary_method) %>%
 # mutate(primary_method = factor(primary_method, levels = c("Qualitative analysis", "Quantitative analysis"))) %>%
  mutate(method_n = sum(weightvec)) %>%
  group_by(Q5,method_n) %>%
  mutate(count = sum(weightvec)) %>% 
  mutate(pct = count/method_n)  %>%
 mutate(pct = paste0(round(pct*100, 1), "%")) %>%
  summarise(Q5 = first(Q5), primary_method=first(primary_method), pct = first(pct), method_n = first(method_n), count = first(count)) %>%
  mutate(issue = "All")

#International/Global Security
weight_table4_igs_sample <- weighted_data %>% filter(!is.na(Q5) & !is.na(primary_method) & Q43 == "International/Global Security") %>% 
  select(Q5, primary_method, secondary_method, weightvec) %>%
  filter(primary_method == "Qualitative analysis" | primary_method == "Quantitative analysis" | str_detect(secondary_method, "Quantitative analysis")) %>%
  
  mutate(primary_method = case_when(str_detect(secondary_method, "Quantitative analysis") & primary_method != "Qualitative analysis"  ~ "Quantitative analysis", 
                                    TRUE ~ as.character(primary_method))) %>%
  group_by(primary_method) %>%
  mutate(method_n = sum(weightvec)) %>%
  group_by(Q5,method_n) %>%
  mutate(count = sum(weightvec)) %>% 
  mutate(pct = count/method_n)  %>%
 mutate(pct = paste0(round(pct*100, 1), "%")) %>%
  summarise(Q5 = first(Q5), primary_method=first(primary_method), pct = first(pct), method_n = first(method_n), count = first(count))  %>%
  mutate(issue = "International/Global Security")


#get ns for bottom row 
method_n_igs <- weight_table4_igs_sample  %>% select(primary_method, method_n) %>% mutate(method_n = round(method_n,1)) %>% pivot_wider(names_from = primary_method, values_from = method_n) %>% mutate(across(everything(), as.character))
method_n <- weight_table4_full_sample  %>% select(primary_method, method_n) %>% mutate(method_n = round(method_n,1)) %>% pivot_wider(names_from = primary_method, values_from = method_n) %>% mutate(across(everything(), as.character))
method_ns <- cbind(method_n[1,2:3],  method_n_igs[1,2:3])

#get tables
weight_table4_igs_sample <- weight_table4_igs_sample %>% select(Q5, primary_method, pct) %>% pivot_wider(names_from = primary_method, values_from = pct)
weight_table4_full_sample <- weight_table4_full_sample %>% select(Q5, primary_method, pct) %>% pivot_wider(names_from = primary_method, values_from = pct)

#create full table
weight_table4_full_table <-  weight_table4_full_sample %>% left_join(weight_table4_igs_sample, by = "Q5") %>%
  mutate(Q5 = factor(Q5, levels = c("Monthly", "Several times a year", "Once every few years", "Never"))) %>% 
  arrange(Q5)
#force ns to conform 
method_ns <- cbind("N", method_ns) 
colnames(method_ns) = colnames(weight_table4_full_table) 
##add Ns to table
weight_table4_full_table <- weight_table4_full_table %>% bind_rows(method_ns)

weight_table4<- weight_table4_full_table %>% kable(booktabs = TRUE,
  col.names= c("Engagement freq.", "Quantitative", "Qualitative", "Quantitative ", "Qualitative"), 
  caption="[Weighted] In the past five years, how frequently have you engaged in the policy-related activities that you identified above?")  %>% 
  add_header_above(c("", "All scholars" = 2, "International/Global Security" = 2)) %>% 
  kable_styling(latex_options = "HOLD_position") 


weight_table4


```








## Manuscript Table 5


```{r table5, include=TRUE}

### Unweighted

#all schoalars
table5_full_sample <- weighted_data %>% filter(!is.na(Q9_1) & !is.na(primary_method)) %>% 
  mutate(Q9_1_recode = case_when(
    Q9_1 == "Agree" | Q9_1 == "Strongly agree" ~ "Agree", 
    Q9_1 == "Disagree" | Q9_1 == "Strongly disagree" ~ "Disagree", 
    Q9_1 == "Neither agree nor disagree" ~ "Neither")) %>%
  select(Q9_1_recode, primary_method, secondary_method) %>%
  filter(primary_method == "Qualitative analysis" | primary_method == "Quantitative analysis" | str_detect(secondary_method, "Quantitative analysis")) %>%
  
  mutate(primary_method = case_when(str_detect(secondary_method, "Quantitative analysis") & primary_method != "Qualitative analysis"  ~ "Quantitative analysis", 
                                    TRUE ~ as.character(primary_method))) %>%
  group_by(primary_method) %>%
  mutate(method_n = n()) %>%
  group_by(Q9_1_recode,method_n) %>%
  mutate(count = n()) %>% 
  mutate(pct = count/method_n)  %>%
 mutate(pct = paste0(round(pct*100, 1), "%")) %>%
  summarise(Q9_1_recode = first(Q9_1_recode), primary_method=first(primary_method), pct = first(pct), method_n = first(method_n), count = first(count)) %>%
  mutate(issue = "All")

#all International/Global Security
table5_igs_sample <- weighted_data %>% filter(!is.na(Q9_1) & !is.na(primary_method)  & Q43 == "International/Global Security") %>% 
  mutate(Q9_1_recode = case_when(
    Q9_1 == "Agree" | Q9_1 == "Strongly agree" ~ "Agree", 
    Q9_1 == "Disagree" | Q9_1 == "Strongly disagree" ~ "Disagree", 
    Q9_1 == "Neither agree nor disagree" ~ "Neither")) %>%
  select(Q9_1_recode, primary_method, secondary_method) %>%
  filter(primary_method == "Qualitative analysis" | primary_method == "Quantitative analysis" | str_detect(secondary_method, "Quantitative analysis")) %>%
  
  mutate(primary_method = case_when(str_detect(secondary_method, "Quantitative analysis") & primary_method != "Qualitative analysis"  ~ "Quantitative analysis", 
                                    TRUE ~ as.character(primary_method))) %>%
  group_by(primary_method) %>%
  mutate(method_n = n()) %>%
  group_by(Q9_1_recode,method_n) %>%
  mutate(count = n()) %>% 
  mutate(pct = count/method_n)  %>%
 mutate(pct = paste0(round(pct*100, 1), "%")) %>%
  summarise(Q9_1_recode = first(Q9_1_recode), primary_method=first(primary_method), pct = first(pct), method_n = first(method_n), count = first(count)) %>%
  mutate(issue = "International/Global Security")

#get ns for bottom row 
method_n_igs <- table5_igs_sample  %>% select(primary_method, method_n) %>% pivot_wider(names_from = primary_method, values_from = method_n) %>% mutate(across(everything(), as.character))
method_n <- table5_full_sample  %>% select(primary_method, method_n) %>% pivot_wider(names_from = primary_method, values_from = method_n) %>% mutate(across(everything(), as.character))
method_ns <- cbind(method_n[1,2:3],  method_n_igs[1,2:3])

#get tables
table5_igs_sample <- table5_igs_sample %>% select(Q9_1_recode, primary_method, pct) %>%  pivot_wider(names_from = primary_method, values_from = pct)
table5_full_sample <- table5_full_sample %>% select(Q9_1_recode, primary_method, pct) %>%  pivot_wider(names_from = primary_method, values_from = pct)
#create full table
table5_full_table <-  table5_full_sample %>% left_join(table5_igs_sample, by = "Q9_1_recode")

#force ns to conform 
method_ns <- cbind("N", method_ns) 
colnames(method_ns) = colnames(table5_full_table) 
##add Ns to table
table5_full_table <- table5_full_table %>% bind_rows(method_ns)



table5<- table5_full_table %>% kable(
  col.names= c("Engagement freq.", "Quantitative", "Qualitative", "Quantitative ", "Qualitative"), 
  booktabs = TRUE,
  caption="[Unweighted] Policy engagement should be a standard part of academic employment, like research, teaching, and service.")  %>% 
  add_header_above(c("", "All scholars" = 2, "International/Global Security" = 2)) %>% 
 kable_styling(latex_options = "HOLD_position") 

table5





### Unweighted

#all schoalars
weight_table5_full_sample <- weighted_data %>% filter(!is.na(Q9_1) & !is.na(primary_method)) %>% 
  mutate(Q9_1_recode = case_when(
    Q9_1 == "Agree" | Q9_1 == "Strongly agree" ~ "Agree", 
    Q9_1 == "Disagree" | Q9_1 == "Strongly disagree" ~ "Disagree", 
    Q9_1 == "Neither agree nor disagree" ~ "Neither")) %>%
  select(Q9_1_recode, primary_method, secondary_method, weightvec) %>%
 filter(primary_method == "Qualitative analysis" | primary_method == "Quantitative analysis" | str_detect(secondary_method, "Quantitative analysis")) %>%
  
  mutate(primary_method = case_when(str_detect(secondary_method, "Quantitative analysis") & primary_method != "Qualitative analysis"  ~ "Quantitative analysis", 
                                    TRUE ~ as.character(primary_method))) %>%
  group_by(primary_method) %>%
  mutate(method_n = sum(weightvec)) %>%
  group_by(Q9_1_recode,method_n) %>%
  mutate(count =  sum(weightvec)) %>% 
  mutate(pct = count/method_n)  %>%
 mutate(pct = paste0(round(pct*100, 1), "%")) %>%
  summarise(Q9_1_recode = first(Q9_1_recode), primary_method=first(primary_method), pct = first(pct), method_n = first(method_n), count = first(count)) %>%
  mutate(issue = "All")

#all International/Global Security
weight_table5_igs_sample <- weighted_data %>% filter(!is.na(Q9_1) & !is.na(primary_method)  & Q43 == "International/Global Security") %>% 
  mutate(Q9_1_recode = case_when(
    Q9_1 == "Agree" | Q9_1 == "Strongly agree" ~ "Agree", 
    Q9_1 == "Disagree" | Q9_1 == "Strongly disagree" ~ "Disagree", 
    Q9_1 == "Neither agree nor disagree" ~ "Neither")) %>%
  select(Q9_1_recode, primary_method, secondary_method, weightvec) %>%
 filter(primary_method == "Qualitative analysis" | primary_method == "Quantitative analysis" | str_detect(secondary_method, "Quantitative analysis")) %>%
  
  mutate(primary_method = case_when(str_detect(secondary_method, "Quantitative analysis") & primary_method != "Qualitative analysis"  ~ "Quantitative analysis", 
                                    TRUE ~ as.character(primary_method))) %>%
  group_by(primary_method) %>%
  mutate(method_n =  sum(weightvec)) %>%
  group_by(Q9_1_recode,method_n) %>%
  mutate(count =  sum(weightvec)) %>% 
  mutate(pct = count/method_n)  %>%
 mutate(pct = paste0(round(pct*100, 1), "%")) %>%
  summarise(Q9_1_recode = first(Q9_1_recode), primary_method=first(primary_method), pct = first(pct), method_n = first(method_n), count = first(count)) %>%
  mutate(issue = "International/Global Security")

#get ns for bottom row 
method_n_igs <- weight_table5_igs_sample  %>% select(primary_method, method_n) %>% mutate(method_n = round(method_n,1)) %>%  pivot_wider(names_from = primary_method, values_from = method_n) %>% mutate(across(everything(), as.character))
method_n <- weight_table5_full_sample  %>% select(primary_method, method_n) %>% mutate(method_n = round(method_n,1)) %>% pivot_wider(names_from = primary_method, values_from = method_n) %>% mutate(across(everything(), as.character))
method_ns <- cbind(method_n[1,2:3],  method_n_igs[1,2:3])

#get tables
weight_table5_igs_sample <- weight_table5_igs_sample %>% select(Q9_1_recode, primary_method, pct) %>%  pivot_wider(names_from = primary_method, values_from = pct)
weight_table5_full_sample <- weight_table5_full_sample %>% select(Q9_1_recode, primary_method, pct) %>%  pivot_wider(names_from = primary_method, values_from = pct)
#create full table
weight_table5_full_table <-  weight_table5_full_sample %>% left_join(weight_table5_igs_sample, by = "Q9_1_recode")

#force ns to conform 
method_ns <- cbind("N", method_ns) 
colnames(method_ns) = colnames(weight_table5_full_table) 
##add Ns to table
weight_table5_full_table <- weight_table5_full_table %>% bind_rows(method_ns)



weight_table5<- weight_table5_full_table %>% kable(
  col.names= c("Engagement freq.", "Quantitative", "Qualitative", "Quantitative ", "Qualitative"), 
  booktabs = TRUE,
  caption="[Weighted] Policy engagement should be a standard part of academic employment, like research, teaching, and service.")  %>% 
  add_header_above(c("", "All scholars" = 2, "International/Global Security" = 2)) %>% 
  kable_styling(latex_options = "HOLD_position") 
weight_table5




```




## Manuscript Table 6

```{r table6, include=TRUE}


##unweighted 
#all schoalars
table6_full_sample <- weighted_data %>% filter(!is.na(Q9_10) & !is.na(primary_method)) %>% 
  mutate(Q9_10_recode = case_when(
    Q9_10 == "Agree" | Q9_10 == "Strongly agree" ~ "Agree", 
    Q9_10 == "Disagree" | Q9_10 == "Strongly disagree" ~ "Disagree", 
    Q9_10 == "Neither agree nor disagree" ~ "Neither")) %>%
  select(Q9_10_recode, primary_method, secondary_method) %>%
  filter(primary_method == "Qualitative analysis" | primary_method == "Quantitative analysis" | str_detect(secondary_method, "Quantitative analysis")) %>%
  
  mutate(primary_method = case_when(str_detect(secondary_method, "Quantitative analysis") & primary_method != "Qualitative analysis"  ~ "Quantitative analysis", 
                                    TRUE ~ as.character(primary_method))) %>%
  group_by(primary_method) %>%
  mutate(method_n = n()) %>%
  group_by(Q9_10_recode,method_n) %>%
  mutate(count = n()) %>% 
  mutate(pct = count/method_n)  %>%
 mutate(pct = paste0(round(pct*100, 1), "%")) %>%
  summarise(Q9_10_recode = first(Q9_10_recode), primary_method=first(primary_method), pct = first(pct), method_n = first(method_n), count = first(count)) %>%
  mutate(issue = "All")

#International/Global Security scholars
table6_igs_sample <- weighted_data %>% filter(!is.na(Q9_10) & !is.na(primary_method) & Q43 == "International/Global Security") %>% 
  mutate(Q9_10_recode = case_when(
    Q9_10 == "Agree" | Q9_10 == "Strongly agree" ~ "Agree", 
    Q9_10 == "Disagree" | Q9_10 == "Strongly disagree" ~ "Disagree", 
    Q9_10 == "Neither agree nor disagree" ~ "Neither")) %>%
  select(Q9_10_recode, primary_method, secondary_method) %>%
  filter(primary_method == "Qualitative analysis" | primary_method == "Quantitative analysis" | str_detect(secondary_method, "Quantitative analysis")) %>%
  
  mutate(primary_method = case_when(str_detect(secondary_method, "Quantitative analysis") & primary_method != "Qualitative analysis"  ~ "Quantitative analysis", 
                                    TRUE ~ as.character(primary_method))) %>%
  group_by(primary_method) %>%
  mutate(method_n = n()) %>%
  group_by(Q9_10_recode,method_n) %>%
  mutate(count = n()) %>% 
  mutate(pct = count/method_n)  %>%
 mutate(pct = paste0(round(pct*100, 1), "%")) %>%
  summarise(Q9_10_recode = first(Q9_10_recode), primary_method=first(primary_method), pct = first(pct), method_n = first(method_n), count = first(count)) %>%
  mutate(issue = "All")

#get ns for bottom row 
method_n_igs <- table6_igs_sample  %>% select(primary_method, method_n) %>% pivot_wider(names_from = primary_method, values_from = method_n) %>% mutate(across(everything(), as.character))
method_n <- table6_full_sample  %>% select(primary_method, method_n) %>% pivot_wider(names_from = primary_method, values_from = method_n) %>% mutate(across(everything(), as.character))
method_ns <- cbind(method_n[1,2:3],  method_n_igs[1,2:3])

#get tables
table6_igs_sample <- table6_igs_sample %>% select(Q9_10_recode, primary_method, pct) %>%  pivot_wider(names_from = primary_method, values_from = pct)
table6_full_sample <- table6_full_sample %>% select(Q9_10_recode, primary_method, pct) %>%  pivot_wider(names_from = primary_method, values_from = pct)
#create full table
table6_full_table <-  table6_full_sample %>% left_join(table6_igs_sample, by = "Q9_10_recode")

#force ns to conform 
method_ns <- cbind("N", method_ns) 
colnames(method_ns) = colnames(table6_full_table) 
##add Ns to table
table6_full_table <- table6_full_table %>% bind_rows(method_ns)


table6<- table6_full_table %>% kable(
  col.names= c("Engagement freq.", "Quantitative", "Qualitative", "Quantitative ", "Qualitative"), 
  booktabs = TRUE,
  caption="[Unweighted]  My university should value policy engagement in the tenure and promotion process." ) %>% 
  add_header_above(c("", "All scholars" = 2, "International/Global Security" = 2)) %>% 
  kable_styling(latex_options = "HOLD_position") 

table6





##unweighted 
#all schoalars
weight_table6_full_sample <- weighted_data %>% filter(!is.na(Q9_10) & !is.na(primary_method)) %>% 
  mutate(Q9_10_recode = case_when(
    Q9_10 == "Agree" | Q9_10 == "Strongly agree" ~ "Agree", 
    Q9_10 == "Disagree" | Q9_10 == "Strongly disagree" ~ "Disagree", 
    Q9_10 == "Neither agree nor disagree" ~ "Neither")) %>%
  select(Q9_10_recode, primary_method, secondary_method, weightvec) %>%
  filter(primary_method == "Qualitative analysis" | primary_method == "Quantitative analysis" | str_detect(secondary_method, "Quantitative analysis")) %>%
  
  mutate(primary_method = case_when(str_detect(secondary_method, "Quantitative analysis") & primary_method != "Qualitative analysis"  ~ "Quantitative analysis", 
                                    TRUE ~ as.character(primary_method))) %>%
  group_by(primary_method) %>%
  mutate(method_n = sum(weightvec)) %>%
  group_by(Q9_10_recode, method_n) %>%
  mutate(count = sum(weightvec)) %>% 
  mutate(pct = count/method_n)  %>%
 mutate(pct = paste0(round(pct*100, 1), "%")) %>%
  summarise(Q9_10_recode = first(Q9_10_recode), primary_method=first(primary_method), pct = first(pct), method_n = first(method_n), count = first(count)) %>%
  mutate(issue = "All")

#International/Global Security scholars
weight_table6_igs_sample <- weighted_data %>% filter(!is.na(Q9_10) & !is.na(primary_method) & Q43 == "International/Global Security") %>% 
  mutate(Q9_10_recode = case_when(
    Q9_10 == "Agree" | Q9_10 == "Strongly agree" ~ "Agree", 
    Q9_10 == "Disagree" | Q9_10 == "Strongly disagree" ~ "Disagree", 
    Q9_10 == "Neither agree nor disagree" ~ "Neither")) %>%
  select(Q9_10_recode, primary_method, secondary_method, weightvec) %>%
filter(primary_method == "Qualitative analysis" | primary_method == "Quantitative analysis" | str_detect(secondary_method, "Quantitative analysis")) %>%
  
  mutate(primary_method = case_when(str_detect(secondary_method, "Quantitative analysis") & primary_method != "Qualitative analysis"  ~ "Quantitative analysis", 
                                    TRUE ~ as.character(primary_method))) %>%
  group_by(primary_method) %>%
  mutate(method_n = sum(weightvec)) %>%
  group_by(Q9_10_recode,method_n) %>%
  mutate(count = sum(weightvec)) %>% 
  mutate(pct = count/method_n)  %>%
 mutate(pct = paste0(round(pct*100, 1), "%")) %>%
  summarise(Q9_10_recode = first(Q9_10_recode), primary_method=first(primary_method), pct = first(pct), method_n = first(method_n), count = first(count)) %>%
  mutate(issue = "All")

#get ns for bottom row 
method_n_igs <- weight_table6_igs_sample  %>% select(primary_method, method_n) %>% mutate(method_n = round(method_n,1)) %>% pivot_wider(names_from = primary_method, values_from = method_n) %>% mutate(across(everything(), as.character))
method_n <- weight_table6_full_sample  %>% select(primary_method, method_n) %>% mutate(method_n = round(method_n,1))  %>% pivot_wider(names_from = primary_method, values_from = method_n) %>% mutate(across(everything(), as.character))
method_ns <- cbind(method_n[1,2:3],  method_n_igs[1,2:3])

#get tables
weight_table6_igs_sample <- weight_table6_igs_sample %>% select(Q9_10_recode, primary_method, pct) %>%  pivot_wider(names_from = primary_method, values_from = pct)
weight_table6_full_sample <- weight_table6_full_sample %>% select(Q9_10_recode, primary_method, pct) %>%  pivot_wider(names_from = primary_method, values_from = pct)
#create full table
weight_table6_full_table <-  weight_table6_full_sample %>% left_join(weight_table6_igs_sample, by = "Q9_10_recode")

#force ns to conform 
method_ns <- cbind("N", method_ns) 
colnames(method_ns) = colnames(weight_table6_full_table) 
##add Ns to table
weight_table6_full_table <- weight_table6_full_table %>% bind_rows(method_ns)


weight_table6<- weight_table6_full_table %>% kable(
  col.names= c("Engagement freq.", "Quantitative", "Qualitative", "Quantitative ", "Qualitative"), 
  booktabs = TRUE,
  caption="[Weighted]  My university should value policy engagement in the tenure and promotion process.")  %>% 
  add_header_above(c("", "All scholars" = 2, "International/Global Security" = 2)) %>% 
  kable_styling(latex_options = "HOLD_position") 

weight_table6




```



From the manuscript: "Only 31% of respondents agreed or strongly agreed their university currently values policy engagement in the tenure and promotion process, with 44 percent disagreeing or strongly disagreeing." 

```{r in_text20, include=TRUE}

weighted_data %>% mutate(Q9_9_recode = case_when(
  Q9_9 == "Disagree" |  Q9_9 == "Strongly disagree" ~ "Disagree or strongly disagree", 
  Q9_9 == "Agree" |  Q9_9 == "Strongly agree" ~ "Agree or strongly agree", 
  !is.na(Q9_9) ~ "Neither agree nor disagree, agree, or strongly agree")) %>%
  tabyl(Q9_9_recode, show_na = FALSE) %>% adorn_pct_formatting()  %>%
  kable(caption = "", 
        booktabs = TRUE, 
        linesep = "",
        digit = 2, 
        col.names= c("Response option", "N", "Percent"))  %>% 
  kable_styling(latex_options = "HOLD_position") 

```

From the manuscript: "This stands in stark contrast to beliefs about whether these activities should count in promotion decisions: 63% agreed or strongly agreed their university should value policy engagement in the tenure and promotion process, with only 16% disagreeing or strongly disagreeing."

```{r in_text21, include=TRUE}

weighted_data %>% mutate(Q9_10_recode = case_when(
  Q9_10 == "Disagree" |  Q9_10 == "Strongly disagree" ~ "Disagree or strongly disagree", 
  Q9_10 == "Agree" |  Q9_10 == "Strongly agree" ~ "Agree or strongly agree", 
  !is.na(Q9_10) ~ "Neither agree nor disagree, agree, or strongly agree")) %>%
  tabyl(Q9_10_recode, show_na = FALSE) %>% adorn_pct_formatting()  %>%
  kable(caption = "", 
        booktabs = TRUE, 
        linesep = "",
        digit = 2, 
        col.names= c("Response option", "N", "Percent"))  %>% 
  kable_styling(latex_options = "HOLD_position") 

```


From the manuscript: "An overwhelming majority (87.1%) of respondents agreed with the statement, “In the event that their policy recommendations come to be adopted by policymakers, scholars bear at least partial responsibility for the impact of those policies in the real world.""

```{r in_text22, include=TRUE}

weighted_data %>% mutate(Q14_recode = case_when(
  Q14  == "Disagree" |  Q14  == "Strongly disagree" ~ "Disagree or strongly disagree", 
  Q14  == "Agree" |  Q14  == "Strongly agree" ~ "Agree or strongly agree", 
  !is.na(Q14 ) ~ "Neither agree nor disagree, agree, or strongly agree")) %>%
  tabyl(Q14_recode, show_na = FALSE) %>% adorn_pct_formatting()  %>%
  kable(caption = "", 
        booktabs = TRUE, 
        linesep = "",
        digit = 2, 
        col.names= c("Response option", "N", "Percent"))  %>% 
  kable_styling(latex_options = "HOLD_position") 

```
From the manuscript: "Interestingly, very few IR scholars (4.7%) self-identified as having tempered or withheld their true beliefs or opinions in anticipation that the sponsor of those activities might disapprove."

```{r in_text23, include=TRUE}

weighted_data %>% mutate(Q22_recode = case_when(
  Q22  == "Disagree" |  Q22  == "Strongly disagree" ~ "Disagree or strongly disagree", 
  Q22  == "Agree" |  Q22  == "Strongly agree" ~ "Agree or strongly agree", 
  !is.na(Q22 ) ~ "Neither agree nor disagree, agree, or strongly agree")) %>%
  tabyl(Q22_recode, show_na = FALSE) %>% adorn_pct_formatting()  %>%
  kable(caption = "", 
        booktabs = TRUE, 
        linesep = "",
        digit = 2, 
        col.names= c("Response option", "N", "Percent"))  %>% 
  kable_styling(latex_options = "HOLD_position") 

```



From the manuscript: "Overall, IR scholars were again divided, with 36% agreeing that they valued their own conclusions over scholarly consensus, 29.4% disagreeing, and 32.5% neither agreeing nor disagreeing. Seniority clearly mattered, however, with each rung up the academic ladder conferring greater confidence in one’s own findings."


```{r in_text24, include=TRUE}

weighted_data %>% mutate(Q9_7_recode = case_when(
  Q9_7  == "Disagree" |  Q9_7  == "Strongly disagree" ~ "Disagree or strongly disagree", 
  Q9_7  == "Agree" |  Q9_7  == "Strongly agree" ~ "Agree or strongly agree", 
  !is.na(Q9_7) ~ "Neither agree nor disagree, agree, or strongly agree")) %>%
  tabyl(Q9_7_recode, show_na = FALSE) %>% adorn_pct_formatting()  %>%
  kable(caption = "", 
        booktabs = TRUE, 
        linesep = "",
        digit = 2, 
        col.names= c("Response option", "N", "Percent"))  %>% 
  kable_styling(latex_options = "HOLD_position") 

```





\clearpage

## Manuscript Figure 1


```{r fig1, include=TRUE}
# Q24 I worry that policy-engaged scholars distort their true beliefs or opinions to appeal to policy audiences.




plot_theme =  theme_linedraw()+ theme(text = element_text(size=10), 
                                panel.grid.major = element_blank(),
                                panel.grid.minor = element_blank(),
                                panel.grid.major.y = element_line(colour = "#CCCCCC"),
                                #axis.text = element_text(color="black",size=12, angle=0),
                                axis.line = element_line(colour = "black"),
                                strip.text.y = element_text(angle = 0), 
                                axis.title.y = element_text(angle=0, ),
                                #axis.title = element_text(lineheight=1.1, size=14,face="bold"), 
                                strip.background=element_rect(colour=NA, fill="#000000"),
                                #strip.text = element_text(colour = '#000000'),
                                #legend.position="bottom",
                                #strip.text.x = element_text(size = 12), 
                                legend.title=element_blank(), 
                                legend.position="t op",
                                #axis.title=element_text(size=14,face="bold"), 
                                axis.text=element_text(size=10),
                                strip.text.x = element_text(size = 10),
                                legend.text=element_text(size=10), 
                                axis.text.x = element_text(angle = 45, hjust = 1, vjust=1)) 

weighted_data %>% 
  filter(!is.na(Q24)) %>%
  mutate(Q24_recode = case_when(
    Q24 == "Agree" | Q24 == "Strongly agree" ~ "Agree", 
    Q24 == "Disagree" | Q24 == "Strongly disagree" ~ "Disagree", 
    Q24 == "Neither agree nor disagree" ~ "Neither"))  %>%
  select(Q24_recode) %>%
  mutate(n=n()) %>%
  group_by(Q24_recode) %>%
  dplyr::summarize(n = first(n), count = n()) %>% 
  mutate(pct = paste0(round((count/n)*100, 1), "% (", count ,")" )) %>%
  select(Q24_recode, pct) %>%
  kable(col.names= c("", "Pct. (N)"), 
                           caption="[Unweighted] I worry that policy-engaged scholars distort their true beliefs or opinions to appeal to policy audiences.", booktabs = TRUE ) %>%   kable_styling(latex_options = "HOLD_position") 
  

plot_data <- weighted_data %>% 
  filter(!is.na(Q24)) %>%
  mutate(Q24_recode = case_when(
    Q24 == "Agree" | Q24 == "Strongly agree" ~ "Agree", 
    Q24 == "Disagree" | Q24 == "Strongly disagree" ~ "Disagree", 
    Q24 == "Neither agree nor disagree" ~ "Neither"))  %>%
  select(Q24_recode) %>%
  mutate(n=n()) %>%
  group_by(Q24_recode) %>%
  dplyr::summarize(n = first(n), count = n()) %>% 
  mutate(pct = (count/n)*100) %>%
  select(Q24_recode, pct) 

figure1<-ggplot(data=plot_data, (aes(x=Q24_recode, y=pct, label=paste0(round(pct, 1),"%")))) + 
  geom_bar(stat="identity", fill = "#003366") +
  ylab("Percent of\nrespondents") + xlab("Level of agreement") + plot_theme +
  scale_y_continuous( limits = c(0, 100)) +  theme(axis.title.y = element_text(angle=0, vjust = 0.5)) +
  geom_label()
figure1
ggsave("figure1.png", figure1, width=5, height = 5)

```




## Manuscript Table 7 


```{r table7, include=TRUE}



ranks <- c("Chaired Professor", "Full Professor", "Associate Professor", "Assistant Professor", "Other")



table7 <- weighted_data %>% filter(!is.na(Q9_7) & !is.na(academic_rank_raw)) %>% 
  mutate(Q9_7_recode = case_when(
    Q9_7 == "Agree" | Q9_7 == "Strongly agree" ~ "Agree", 
    Q9_7 == "Disagree" | Q9_7 == "Strongly disagree" ~ "Disagree", 
    Q9_7 == "Neither agree nor disagree" ~ "Neither")) %>%
  mutate(academic_rank_recode = academic_rank_raw) %>%
  mutate(academic_rank_recode = case_when(
    academic_rank_recode != "Assistant Professor" &  
    academic_rank_recode != "Associate Professor" &
    academic_rank_recode != "Full Professor" &  
    academic_rank_recode != "Chaired Professor" &  
    !is.na(academic_rank_recode)  ~ "Other", 
    TRUE ~ academic_rank_recode)) %>%
  select(Q9_7_recode, academic_rank_recode) %>%
  group_by(academic_rank_recode) %>%
  mutate(rank_n = n()) %>%
  group_by(Q9_7_recode,rank_n) %>%
  mutate(count = n()) %>% 
  mutate(pct = count/rank_n)  %>%
 mutate(pct = paste0(round(pct*100, 1), "% (", count ,")" )) %>%
  summarise(Q9_7_recode = first(Q9_7_recode), academic_rank_recode=first(academic_rank_recode), pct = first(pct), rank_n = first(rank_n), count = first(count)) %>% 
  mutate(academic_rank_recode = factor(academic_rank_recode, levels = ranks )) %>% arrange(academic_rank_recode) %>% select(academic_rank_recode, Q9_7_recode,pct ) %>%
  pivot_wider(names_from=Q9_7_recode, values_from = pct) %>% kable(col.names= c("Rank", "Agree", "Disagree", "Neither"),  booktabs = TRUE,
                                                                   caption="[Unweighted] In policy discussions, I value the conclusions of my own research over the scholarly consensus on an issue by rank" ) %>% kable_styling(latex_options = "HOLD_position") 
table7

table7_weighted <- weighted_data %>% filter(!is.na(Q9_7) & !is.na(academic_rank_raw)) %>% 
  mutate(Q9_7_recode = case_when(
    Q9_7 == "Agree" | Q9_7 == "Strongly agree" ~ "Agree", 
    Q9_7 == "Disagree" | Q9_7 == "Strongly disagree" ~ "Disagree", 
    Q9_7 == "Neither agree nor disagree" ~ "Neither")) %>%
  mutate(academic_rank_recode = academic_rank_raw) %>%
  mutate(academic_rank_recode = case_when(
    academic_rank_recode != "Assistant Professor" &  
    academic_rank_recode != "Associate Professor" &
    academic_rank_recode != "Full Professor" &  
    academic_rank_recode != "Chaired Professor" &  
    !is.na(academic_rank_recode)  ~ "Other", 
    TRUE ~ academic_rank_recode)) %>%
  select(Q9_7_recode, academic_rank_recode, weightvec) %>%
  group_by(academic_rank_recode) %>%
  mutate(rank_n = sum(weightvec)) %>%
  group_by(Q9_7_recode,rank_n) %>%
  mutate(count = sum(weightvec)) %>% 
  mutate(pct = count/rank_n)  %>%
 mutate(pct = paste0(round(pct*100, 1), "% (", round(count,1) ,")" )) %>%
  summarise(Q9_7_recode = first(Q9_7_recode), academic_rank_recode=first(academic_rank_recode), pct = first(pct), rank_n = first(rank_n), count = first(count)) %>% 
  mutate(academic_rank_recode = factor(academic_rank_recode, levels = ranks )) %>% arrange(academic_rank_recode) %>% select(academic_rank_recode, Q9_7_recode,pct ) %>%
  pivot_wider(names_from=Q9_7_recode, values_from = pct) %>% 
  kable(col.names= c("Rank", "Agree", "Disagree", "Neither"), booktabs = TRUE, caption="[Weighted] In policy discussions, I value the conclusions of my own research over the scholarly consensus on an issue by rank" ) %>% 
  kable_styling(latex_options = "HOLD_position") 
table7_weighted


```


\clearpage

# References





